var currentImage;
	var currentIndex = -1;
	var interval;
	function showImage(index){
			if(index < $('#bigPic img').length){
				var indexImage = $('#bigPic img')[index]
					if(currentImage){   
						if(currentImage != indexImage ){
									$(currentImage).css('z-index',2);
									clearTimeout(myTimer);
									$(currentImage).fadeOut(300, function() {
						myTimer = setTimeout("showNext()", 5000);
						$(this).css({'display':'none','z-index':1})
				});
							}
					}
					$(indexImage).css({'display':'block', 'opacity':1});
					currentImage = indexImage;
					currentIndex = index;
					$('#thumbs li').removeClass('active');
					$($('#thumbs li')[index]).addClass('active');
			}
	}
	
	function showNext(){
			var len = $('#bigPic img').length;
			var next = currentIndex < (len-1) ? currentIndex + 1 : 0;
			showImage(next);
	}
	
	var myTimer;
	
	$(document).ready(function() {
		myTimer = setTimeout("showNext()", 5000);
	showNext(); //loads first image
			$('#thumbs li').bind('click',function(e){
				var count = $(this).attr('rel');
				showImage(parseInt(count)-1);
			});
});


var currentImage_2;
	var currentIndex_2 = -1;
	var interval_2;
	function showImage_2(index){
			if(index < $('#bigPic_2 img').length){
				var indexImage_2 = $('#bigPic_2 img')[index]
					if(currentImage_2){   
						if(currentImage_2 != indexImage_2 ){
									$(currentImage_2).css('z-index',2);
									clearTimeout(myTimer_2);
									$(currentImage_2).fadeOut(300, function() {
						myTimer_2 = setTimeout("showNext_2()", 5000);
						$(this).css({'display':'none','z-index':1})
				});
							}
					}
					$(indexImage_2).css({'display':'block', 'opacity':1});
					currentImage_2 = indexImage_2;
					currentIndex_2 = index;
			}
	}
	
	function showNext_2(){
			var len_2 = $('#bigPic_2 img').length;
			var next_2 = currentIndex_2 < (len_2-1) ? currentIndex_2 + 1 : 0;
			showImage_2(next_2);
	}
	
	var myTimer_2;
	
	$(document).ready(function() {
		myTimer_2 = setTimeout("showNext_2()", 5000);
	showNext_2(); //loads first image
			$('#thumbs li').bind('click',function(e){
				var count = $(this).attr('rel');
				showImage_2(parseInt(count)-1);
			});
});